<template>
	<!-- 电子发票列表 -->
	<view class="doctor-container">
		<view class="screenType">
			<view class="typeLeft">
				<uni-datetime-picker type="date" :end="endTime" v-model="beginTime"
					@change="beginChange($event)">{{beginTime}}</uni-datetime-picker>
				<view style="margin: 0 10rpx;">-</view>
				<uni-datetime-picker type="date" :start="beginTime" v-model="endTime"
					@change="endChange($event)">{{endTime}}</uni-datetime-picker>
			</view>
		</view>
		<scroll-view class="scroll-view_H" scroll-y="true">
			<view class="flex flex-column align-center">
				<view class="item" v-for="(item,index) in datas" :key="index">
					<view class="flex align-center p-b-20" style="border-bottom: 1px solid #eeeeee;">
						<text class="f-s-30 f-bold">{{item.eInvoiceName}}</text>
					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">电子票据号码</text>
						<text class="color-323232">{{item.eInvoiceNumber}}</text>
					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">住院号/卡号</text>
						<text class="color-323232">{{item.admissionNo}}</text>
					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">业务流水号</text>
						<text class="color-323232">{{item.serialNumber}}</text>
					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">电子票据代码</text>
						<text class="color-323232">{{item.eInvoiceCode}}</text>
					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">校验码</text>
						<text class="color-323232">{{item.randomNumber}}</text>
					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">医院流水号</text>
						<text class="color-323232">{{item.hosOrderNo}}</text>
					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">是否有效</text>
						<text v-if="item.valid==1" style="color: #4D8EFF;">有效</text>						
						<text v-else style="color: #FF6430;">无效</text>					</view>
					<view class="flex align-center justify-between p-t-15 p-b-15 p-l-15 p-r-15">
						<text class="color-999">开立日期</text>
						<text class="color-323232">{{item.rq}}</text>
					</view>

					<view class="to-register" @click="downLoad(item)">
						<u-button type="primary" text="下载发票"></u-button>
					</view>
				</view>
			</view>
			<view v-if="datas.length == 0" class="nodata color-999">
				暂无发票
			</view>
		</scroll-view>
		

	</view>
</template>

<script>
	import { booklist, getDownloadElectBill } from "@/api/home/home.js";
	export default {
		data() {
			return {
				datas: [],
				beginTime: '',
				endTime: '',
			}
		},
		onLoad: function(res) {
			let oneDay = 24 * 60 * 60 * 1000
			this.beginTime = this.$parseTime(new Date(Date.now() - 7 * oneDay), '{y}-{m}-{d}')
			this.endTime = this.$parseTime(new Date(), '{y}-{m}-{d}')
			this.getData();
		},
		methods: {
			/* 开始日期 */
			beginChange(e) {
				this.getData()
			},
			/* 结束日期 */
			endChange(e) {
				this.getData()
			},
			getData() {
				let openid = uni.getStorageSync('openid') || ''
				booklist({
					openId:openid,
					startTime: this.beginTime,
					endTime: this.endTime,
				}).then(res => {
					this.datas = res.rows;
				});
			},
			/* 下载 */
			downLoad(row){
				if(row.fpAdress){
					window.location.href = row.fpAdress;
				}else{
					getDownloadElectBill({
						id: row.id,
						hosOrderNo: row.hosOrderNo,
						eInvoiceCode: row.eInvoiceCode,
						eInvoiceNumber: row.eInvoiceNumber,
					}).then(res => {
						if(res.data.pdfurl){
							window.location.href = res.data.pdfurl;
						}
					});
				}
				
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		height: 100%;

		.doctor-container {
			width: 100%;
			height: 100%;
			background-color: #F6F7F9;

			.to-register {
				width: 100%;
			}

			.scroll-view_H {
				width: 100%;
				height: 100%;
				padding: 24rpx;
				.item {
					width: 100%;
					padding: 20rpx;
					margin-bottom: 20rpx;
					border-radius: 10rpx;
					background-color: #fff;
				}
			}

		}

	}
	.screenType {
		width: 100%;
		padding: 20rpx;
		background-color: rgb(92, 147, 249);
		color: #fff;
		.typeLeft{
			display: flex;
			flex: 1;
			text-align: center;
			align-items: center;
		}
	}
	.nodata{
		padding: 20px;
		text-align: center;
	}
</style>
